class Solution {
public:
    int jump(vector<int>& nums) {
        int pos = 0, res = 0;
        while (pos < nums.size() - 1) {
            int idx = pos + 1;
            res ++ ;
            for (int i = idx; i <= pos + nums[pos]; i ++ ) {
                if (i >= nums.size() - 1) return res;
                if (nums[i] + i >= nums[idx] + idx) idx = i; 
            }
            pos = idx;
        }
        return res;
    }
};
